package test.rocketmq;

import java.util.List;

import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import com.alibaba.rocketmq.common.message.MessageExt;

public class OutMessageListener implements MessageListenerConcurrently {
    /**
     * 默认msgs里只有一条消息，可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
     */
    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
        System.out.println(Thread.currentThread().getName() + " Receive new Message:" + msgs.size());
       // MessageExt msg = msgs.get(0);
        for(MessageExt message : msgs){
			String msg = new String(message.getBody());
			System.out.println("msg data from rocketMQ:"+msg);
			long bornTimestamp = message.getBornTimestamp();
			System.out.println("bornTimestamp :"+ bornTimestamp);
			System.out.println("StoreTimestamp :"+ message.getStoreTimestamp());
			System.out.println("ReconsumeTimes :"+ message.getReconsumeTimes());
			
		}
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }
}